﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RealSense.Light.Core
{
  /// <summary>
  /// The service locator has deliberately been kept internal as we want to encourage
  /// the use of Dependency Injection rather than service location. Internally though, we 
  /// are using this to simplify management of RealSense types that we do not want to
  /// expose externally.
  /// </summary>
  internal class ServiceLocator
  {
    private static ServiceLocator instance;
    private Dictionary<Type, object> services = new Dictionary<Type,object>();

    static ServiceLocator()
    {
      instance = new ServiceLocator();
      instance.AddServices();
    }

    private void AddServices()
    {
      services.Add(typeof(ISenseManager), new SenseManagerHandler());
      services.Add(typeof(IConnection), new ConnectionHandler());
    }

    internal static ServiceLocator Instance
    {
      get
      {
        return instance;
      }
    }

    /// <summary>
    /// Get the service identified by T.
    /// </summary>
    /// <typeparam name="T">The type the service was registered against.</typeparam>
    /// <returns>A populated instance of T.</returns>
    internal T Get<T>()
    {
      return (T)services[typeof(T)];
    }
  }
}
